package com.example.foo.member.dao;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.member.model.Withdraw;
import com.example.foo.member.query.WithdrawQuery;

@org.apache.ibatis.annotations.Mapper
public interface WithdrawDao extends com.example.core.dao.BaseDao<Withdraw, Long> {

	public default PageResult<Withdraw> findWithdraws(WithdrawQuery withdrawQuery, Pageable pageable) {
		QueryWrapper<Withdraw> queryWrapper = createQueryWithBaseIf(withdrawQuery);
		//
		if (withdrawQuery.getState() != null) {
			queryWrapper.eq("state", withdrawQuery.getState());
		}
		if (StringUtils.isNotEmpty(withdrawQuery.getWithdrawNo())) {
			queryWrapper.like("withdraw_no", withdrawQuery.getWithdrawNo());
		}
		if (StringUtils.isNotEmpty(withdrawQuery.getCardHolder())) {
			queryWrapper.eq("card_holder", withdrawQuery.getCardHolder());
		}
		if (StringUtils.isNotEmpty(withdrawQuery.getCardNumber())) {
			queryWrapper.like("card_number", withdrawQuery.getCardNumber());
		}
		if (StringUtils.isNotEmpty(withdrawQuery.getOuterOrderNo())) {
			queryWrapper.like("outer_order_no", withdrawQuery.getOuterOrderNo());
		}
		if (withdrawQuery.getUserId() != null) {
			queryWrapper.eq("user_id", withdrawQuery.getUserId());
		}
		return findPages(queryWrapper, pageable);
	}

}
